package org.recruit.system.controller;

import org.recruit.system.domain.Users;
import org.recruit.system.service.IUsersService;
import org.recruit.system.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 个人用户Controller
 * 
 * @author teapot
 * @date 2020-11-12
 */
@Controller
@RequestMapping("/system/users")
public class UsersController
{
    private String prefix = "system/users";

    @Autowired
    private IUsersService usersService;

    @GetMapping()
    public String users()
    {
        return prefix + "/users";
    }

    /**
     * 查询个人用户列表
     */
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(Users users)
    {
       // startPage();
        List<Users> list = usersService.selectUsersList(users);
        return AjaxResult.success(list);
    }


    /**
     * 新增个人用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存个人用户
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Users users)
    {
        return AjaxResult.success(usersService.insertUsers(users));
    }

    /**
     * 修改个人用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Users users = usersService.selectUsersById(id);
        mmap.put("users", users);
        return prefix + "/edit";
    }

    /**
     * 修改保存个人用户
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Users users)
    {
        return AjaxResult.success(usersService.updateUsers(users));
    }

    /**
     * 删除个人用户
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return AjaxResult.success(usersService.deleteUsersByIds(ids));
    }
}
